Ext.define('PAN.controller.IndexCtrl',{
	extend : 'Ext.app.Controller',
	refs:[
        {ref: 'leftmenu',selector: 'leftmenu'}
    ],
    init:function(){
        this.control({
            'leftmenu': {
                itemclick: this.loadMenu
            }
        });
    },
    loadMenu:function(view, record){
        if (record.get('leaf')) { 
        	var main = Ext.getCmp("center_panel");
        	if(main == null ) return;
        	var tabid = record.get('id');
        	var tab = main.getComponent(tabid);
        	if(tab != null){
        		main.setActiveTab(tab);
        	}else{
	        	var url = record.get('src');
	        	if(url == '' || url == undefined){
	        		url = 'about:blank';
	        	}else if(!(url.indexOf('http') == 0 || url.indexOf('/') == 0)){
	        		url = url;
	        	}
	        	main.add({
	        		id:tabid,
	        		title:record.get('text'),
	        		iconCls: 'tabs',
	        		closable: true ,
	        		bodyStyle: 'padding: 0px;',
	        		html:'<iframe id="if_'+tabid+'" name="if_'+tabid +'" src="'+url+'" width="100%" height="100%" SCROLLING="yes" frameBorder="0" style="border-style:none;"></iframe> '
	        	}).show();
        	}
        } 
    }
});